<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

// php artisan make:migration update_users_for_timestamp --table=users
class UpdateUsersForTimestamp extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['created_at', 'updated_at']);
            // 不指定长度，会使用 Schema::defaultStringLength(191); 指定的 191。
            $table->string('memo')->after('name')->nullable()->comment('状态');
            // 不知道为什么会在 status 字段后面。
            // $table->string('description', 255)->nullable()->comment('描述');
            $table->string('description', 255)->after('memo')->nullable()->comment('描述');
            // tinyint(4)
            $table->tinyInteger('status')->after('remember_token')->default(1)->comment('状态');
            $table->char('active', 1)->default('1')->comment('是否激活');
            // tinyint(1) NOT NULL，已有数据默认赋值为 0。
            // 后来发现还是需要给默认值。
            $table->boolean('is_delete')->default(0)->comment('是否删除');
            // ->useCurrent() 这是设置默认值。
            $table->timestamp('create_time')->nullable();
            $table->timestamp('update_time')->nullable();
            $table->timestamp('delete_time')->nullable();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['memo', 'description']);
            $table->dropColumn('status');
            $table->dropColumn('active');
            $table->dropColumn('is_delete');
            $table->dropColumn(['create_time', 'update_time', 'delete_time']);
            $table->timestamps();
        });
    }
}
